package ${packageName}.model;

import net.ymate.platform.persistence.annotation.Default;
import net.ymate.platform.persistence.annotation.Entity;
import net.ymate.platform.persistence.annotation.Id;
import net.ymate.platform.persistence.annotation.Property;
import net.ymate.platform.persistence.annotation.Readonly;
<#if (!isUseBaseEntity)>import net.ymate.platform.persistence.jdbc.support.BaseEntity;</#if>
<#if (primaryKeyType == "Serializable")>import java.io.Serializable;</#if>

/**
 * ${modelName?cap_first} generated By EntityGenerator on ${lastUpdateTime?string("yyyy/MM/dd a HH:mm:ss")}
 *
 * @author YMP
 * @version 1.0
 */
@Entity("${tableName}")
@Readonly
public class ${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if> extends <#if (isUseBaseEntity)>BaseEntity<${primaryKeyType}><#else>BaseEntity<${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if>, ${primaryKeyType}></#if> {

	private static final long serialVersionUID = 1L;

	<#list fieldList as field>
	<#if (field.columnName!"undefined") != "undefined">
	@Property(name = "${field.columnName}")</#if>
	private ${field.varType} ${field.varName};

	</#list>

	/**
	 * 构造器
	 */
	public ${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if>() {
	}

	public ${primaryKeyType} getId() {
		return <#if (primaryKeyType == "Serializable")>null<#else>${primaryKeyName}</#if>;
	}

	public void setId(${primaryKeyType} id) {
		<#if (primaryKeyType == "Serializable")>throw new UnsupportedOperationException("View does not included property id.")<#else>this.${primaryKeyName} = id</#if>;
	}

	<#list fieldList as field>
	<#if field.varName != 'id'>
	/**
	 * @return the ${field.varName}
	 */
	public ${field.varType} get${field.varName?cap_first}() {
		return ${field.varName};
	}

	/**
	 * @param ${field.varName} the ${field.varName} to set
	 */
	public void set${field.varName?cap_first}(${field.varType} ${field.varName}) {
		this.${field.varName} = ${field.varName};
	}
	<#elseif field.varName != primaryKeyName>
    /**
     * @return the ${field.varName}
     */
    public ${field.varType} get_${field.varName?cap_first}() {
    	return ${field.varName};
    }

    /**
     * @param ${field.varName} the ${field.varName} to set
     */
    public void set_${field.varName?cap_first}(${field.varType} ${field.varName}) {
    	this.${field.varName} = ${field.varName};
    }
	</#if>

	</#list>

	<#if (isUseChainMode)>
	//
	// Chain
	//

	public static ${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if>Builder builder() {
		return new ${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if>Builder();
	}

	public ${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if>Builder bind() {
    	return new ${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if>Builder(this);
    }

	public static class ${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if>Builder {

		private ${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if> _model;

		public ${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if>Builder() {
			_model = new ${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if>();
		}

		public ${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if>Builder(${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if> model) {
			_model = model;
		}

		public ${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if> build() {
			return _model;
		}

	<#list fieldList as field>
		public ${field.varType} ${field.varName}() {
			return _model.get${field.varName?cap_first}();
		}

		public ${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if>Builder ${field.varName}(${field.varType} ${field.varName}) {
			_model.set${field.varName?cap_first}(${field.varName});
			return this;
		}

	</#list>
	}
	</#if>

	/**
	 * ${modelName?cap_first}<#if (isUseClassSuffix)>Model</#if> 字段常量表
	 */
	public class FIELDS {
	<#list allFieldList as field>
		public static final ${field.varType} ${field.varName} = "${field.columnName}";
	</#list>
	}

	public static final String TABLE_NAME = "${tableName}";

}
